import { createI18n } from 'vue-i18n'
import enUS from './locales/en-US.json'
import zhCN from './locales/zh-CN.json'
import type { I18nTypedSchema, SupportedLocale } from './locales/types'

const i18n = createI18n<[I18nTypedSchema], SupportedLocale>({
  legacy: false,
  locale: 'en-US',
  messages: { 'en-US': enUS, 'zh-CN': zhCN },
  missingWarn: false,
  fallbackWarn: false
})

// 类型安全的动态加载
export async function loadLocale(locale: SupportedLocale) {
  const messages = await import(`./locales/${locale}.json`)
  i18n.global.setLocaleMessage(locale, messages.default)
}

export default i18n